<?php
$email = "kipo@abv.bg";
define('HTML_HEADERS', 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n");
	
if($_POST["name"]  && $_POST["email"])
{
	
	define('__MESSAGE','
		
		<p>Oт: '.$_POST["name"].','.$_POST["email"].','.$_POST["gender"].' на '.$_POST["age"].' г.</p>
		<p>'.$_POST["message"].'</p>
		
		<p> </p>
		
		
		<p>IP: <a href="http://whatismyipaddress.com/ip/'.$_SERVER['REMOTE_ADDR'].'">'.$_SERVER['REMOTE_ADDR'].'</a></p>
		');
	if($_POST["subject"] == 'inq') $subject ='Запитване от консултации - '.$_POST["target"];
	if($_POST["subject"] == 'abn') $subject ='Абониране за семинар - '.$_POST["target"];
	
	mail( $email,
		 $subject,__MESSAGE,
	          HTML_HEADERS."From: ".$_POST["name"]." <".$_POST["email"].">");	
	
}


if($_POST["abonament"] && $_POST["email"])
{
	
	if (checkEmail($_POST['email'])== 0) return;
	
	define('__MESSAGE','
		
		<p>'.$_POST["email"].'</p>
		
		<p>IP: <a href="http://whatismyipaddress.com/ip/'.$_SERVER['REMOTE_ADDR'].'">'.$_SERVER['REMOTE_ADDR'].'</a></p>
		');
	 $subject ='Абониране за новини';
	
	
	mail($email,$subject,__MESSAGE,HTML_HEADERS."From: <".$_POST["email"].">");	
	
}

function checkEmail($email) {
	return preg_match("/^[A-z0-9\.\-]+@(?:[A-z0-9\-]+\.)+[A-z0-9]{1,6}$/", $email);
}

?>